<?php
/**
 * Created by PhpStorm.
 * Author: sitenv@aliyun.com
 * CreateTime: 2021/07/11 16:52
 * Blog：www.myblogs.xyz
 */

namespace app\common\service;


class CommonService
{
    public static function audit($field = 'status', $value = 0 , $default = 1, $model = '')
    {
        $param = input('param.');
        $model = empty($model) ? request()->controller() : $model;
        $class = '\\app\\common\\model\\' . $model;
        if (class_exists($class)) {
            $class_model = new $class();
            if (empty($pk)){
                if (empty($param[$class_model->getPk()])){
                    return false;
                }
                $model_id = $param[$class_model->getPk()];
            }else{
                $model_id = $param[$pk];
            }
            $rows = $class_model->status($model_id, $field, $value, $default);
            if (!$rows){
                return false;
            }
            return true;
        }
        return false;
    }

    public static function delete($model = '')
    {
        $param = input('param.');
        $model = empty($model) ? request()->controller() : $model;
        $class = '\\app\\common\\model\\' . $model;
        if (class_exists($class)) {
            $class_model = new $class();
            if (empty($pk)){
                if (empty($param[$class_model->getPk()])){
                    return false;
                }
                $model_id = $param[$class_model->getPk()];
            }else{
                $model_id = $param[$pk];
            }
            $rows = $class_model->remove($model_id);
            if (!$rows){
                return false;
            }
            return true;
        }
        return false;
    }

}